package com.ruoyi.web.controller.game;

import java.util.List;

import com.ruoyi.game.domain.GameRole;
import com.ruoyi.game.domain.dto.GameRoleAddDTO;
import com.ruoyi.game.domain.dto.GameRolePageDTO;
import com.ruoyi.game.domain.dto.GameRoleUpdateDTO;
import com.ruoyi.game.service.IGameRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 角色职业Controller
 *
 * @author ghostmen
 * @date 2024-10-29
 */
@Validated
@RestController
@RequestMapping("/game/role")
@Api(value = "角色职业", tags = "角色职业接口")
public class GameRoleController extends BaseController {

    @Autowired
    private IGameRoleService gameRoleService;

    /**
     * 查询角色职业列表
     */
    @ApiOperation("查询角色职业列表")
    @PreAuthorize("@ss.hasPermi('game:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(GameRolePageDTO pageDTO) {
        startPage();
        List<GameRole> list = gameRoleService.selectGameRoleList(pageDTO);
        return getDataTable(list);
    }

    /**
     * 获取角色职业详细信息
     */
    @ApiOperation("获取角色职业详细信息")
    @PreAuthorize("@ss.hasPermi('game:role:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId) {
        return success(gameRoleService.selectGameRoleByRoleId(roleId));
    }

    /**
     * 新增角色职业
     */
    @ApiOperation("新增角色职业")
    @PreAuthorize("@ss.hasPermi('game:role:add')")
    @Log(title = "角色职业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GameRoleAddDTO gameRoleAddDTO) {
        gameRoleAddDTO.setLoginUser(getLoginUser());
        return toAjax(gameRoleService.insertGameRole(gameRoleAddDTO));
    }

    /**
     * 修改角色职业
     */
    @ApiOperation("修改角色职业")
    @PreAuthorize("@ss.hasPermi('game:role:edit')")
    @Log(title = "角色职业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GameRoleUpdateDTO gameRoleUpdateDTO) {
        gameRoleUpdateDTO.setLoginUser(getLoginUser());
        return toAjax(gameRoleService.updateGameRole(gameRoleUpdateDTO));
    }

    /**
     * 删除角色职业
     */
    @ApiOperation("删除角色职业")
    @PreAuthorize("@ss.hasPermi('game:role:remove')")
    @Log(title = "角色职业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds) {
        return toAjax(gameRoleService.batchDeleteGameRoleByRoleIds(roleIds));
    }
}
